package S08.first;

import java.util.Arrays;
import java.util.Comparator;

public class F01 {

	public static void main(String[] args) {
		Student[]a= {
				new Student("20240102", "张三", 20, 1.75, 65.5),
				new Student("20240103", "李四", 21, 1.85, 66),
				new Student("20240101", "王五", 19, 1.80, 75.5)
		};
		System.out.println("根据Student的compareTo方法来实现按学号升序排列：");
		Arrays.sort(a);
		for (Student student : a) {
			System.out.println(student);
		}
		System.out.println("按年龄的升序对Student[]进行排序：");
		Arrays.sort(a, new SortByAge()); //按年龄排序，默认按升序排列
		for (Student student : a) {
			System.out.println(student);
		}
		
		System.out.println("按年龄的降序对Student[]进行排序：");
		Arrays.sort(a, new SortByAge().reversed()); //按年龄排序，这里按按降序排列
		for (Student student : a) {
			System.out.println(student);
		}
		
		System.out.println("按身高对Student[]进行升序排序：");
		Arrays.sort(a, new Comparator<Student>() { //创建匿名类对象作为第2个餐宿
			@Override 
			public int compare(Student s1, Student s2) {
				return Double.compare(s1.getHeight(), s2.getHeight()); //按身高排序
			}
		});
		for (Student student : a) {
			System.out.println(student);
		}
	}

}
